import React,{Component} from 'react';
import {HashRouter,BrowserRouter,Route,Switch,Redirect} from 'react-router-dom'


import Login from './pages/login/login.jsx'
import Register from './pages/register/register.jsx'
import Home from './pages/home/home.jsx'
import Asset from './pages/asset/asset.jsx'
import './App.less';

import {getConf} from './api/index.js'
import {saveConf} from './store/action-type'
import {connect} from 'react-redux'

class App extends Component {
  constructor(props){
    super(props);
  }
  componentWillMount(){
    getConf().then(res=>{
       console.log(res,'res')
       this.props.saveConf(res.data)
    }).catch(err=>{console.log(err)})
  }
  render(){
    // const {value,msg}=this.state; //解构
    return (
      <HashRouter  >
        <Switch> 
         <Route path='/login'  component={Login}></Route>
         <Route exact path='/home'  component={Home}></Route>
         <Route path='/register' component={Register}></Route>
         <Route path='/asset' component={Asset}></Route>
         <Redirect to="home" />
         </Switch> 
      </HashRouter>
    );
  }
}

// function mapDispatchProps(dispatch){
//   retrun {
//     saveConf:
//   }
// }
export default connect(state=>state,{saveConf})(App);
